package com.etc.service.impl;

import com.etc.dao.VideoDao;
import com.etc.pojo.Video;
import com.etc.service.VideoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VideoServiceImpl implements VideoService {


    @Autowired
    VideoDao dao;

    /**
     * 增加视频
     */
    @Override
    public void getaddVideo(Video video) {
        dao.addVideo(video);
    }

    /**
     * 根据编号删除视频
     */
    @Override
    public void getDeleteVideo(int videoId) {
        dao.deleteVideo(videoId);
    }

    /**
     * 根据视频编号修改视频
     */
    @Override
    public void getUpdateVideo(Video video) {
        dao.updateVideo(video);
    }

    /**
     * 查询所有视频
     *
     * @return
     */
    @Override
    public List<Video> getQueryVideos() {
        return dao.queryVideos();
    }

    @Override
    public PageInfo<Video> getQueryVideo(int pageNum, int pageSize) {
        //1.开启分页
        PageHelper.startPage(pageNum, pageSize);
        //2.执行查询
        List<Video> list = dao.queryVideos();
        //3.包装
        PageInfo<Video> pageInfo = new PageInfo<>(list);
        return  pageInfo;

    }

    /**
     * 根据course查询对应视频
     */
    @Override
    public Video getqueryVideosType(int videoId) {
        return dao.queryVideosType(videoId);
    }
}
